<template>
	<view>
		<form>
			<view class="cu-form-group">
				<view class="title">分类名称</view>
				<input placeholder="请输入分类名称" name="input" v-model="typeName"></input>
			</view>
		</form>
		
		<view class="padding flex flex-direction">
			<button style="background-color: #38628E;border-radius: 30px;height: 40px;line-height: 40px;" class="send-btn" type="primary"
				@click="submitCmt">添&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;加</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				disabled: false,
				loading: false,
				typeName: ""
			};
		},
		methods: {
			submitCmt() {
				if (this.disabled || this.loading) {
					return
				}
				if (this.typeName == '' || this.typeName == null) {
					this.fetch.toast("分类名称不能为空")
					return
				}
				this.disabled = true
				this.loading = true
				this.fetch.request("/type", "POST", {
					typeName: this.typeName,
				}, false, true, false, this)
				.then((res) => {
					this.disabled = false
					this.loading = false
					this.fetch.toast(res.msg, "", res.code == 0)
					uni.navigateBack();
				}).catch(() => {
					this.disabled = false
					this.loading = false
				})
			}
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
	.send-btn {
		width: 100%;
		margin-top: 15px;
		border-radius: 6rpx;
	}
	page{
		background-color: #F9F9F9;
	}
</style>
